package com.im.service.projectInfo.smo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.im.viewmodel.fundPlan.FileVo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.im.MDA;
import com.im.service.common.dao.IFileQueryDAO;
import com.im.service.dto.BaseException;
import com.im.service.dto.BusiConstParamVal;
import com.im.service.dto.FileUpload;
import com.im.service.dto.FundSource;
import com.im.service.dto.ImplementProject;
import com.im.service.dto.PageQuery;
import com.im.service.dto.PlanProject;
import com.im.service.dto.ProjStats;
import com.im.service.dto.ProjectStage;
import com.im.service.planDeclareSet.dao.IPlanDeclareSetQueryDAO;
import com.im.service.projectInfo.dao.IFundSourceQueryDAO;
import com.im.service.projectInfo.dao.IImplementProjQueryDAO;
import com.im.service.projectInfo.dao.IPlanProjectQueryDAO;
import com.im.util.JsonUtil;
import com.im.util.ReturnsUtil;
import com.im.util.StringUtil;
import com.im.viewmodel.projectInfo.ProjProceSubmitListReqVo;
import com.im.viewmodel.projectInfo.ProjProceSubmitListRespVo;

import net.sf.json.JSONObject;

/** 
 * 项目信息管理
 * @author xuwb
 * 2018年3月24日
 */
@Service
public class ProjectInfoQuerySMOImpl implements IProjectInfoQuerySMO {

	private static final Logger logger = LogManager.getLogger(ProjectInfoQuerySMOImpl.class);
	
	@Autowired
	private IPlanProjectQueryDAO planProjectQueryDAO;
	@Autowired
	private IFundSourceQueryDAO fundSourceQueryDAO;
	@Autowired
	private IImplementProjQueryDAO implementProjQueryDAO;
//	@Autowired
//	private IPlanDeclareSetQueryDAO planDeclareSetQueryDAO;
	
	@Autowired
	private IFileQueryDAO fileQueryDAO;
	
	@Override
	public PageQuery<PlanProject> queryPlanProjList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			PageQuery<PlanProject> page = null;
			JSONObject jsonObj = JSONObject.fromObject(inJson);
			if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
				JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
				page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
				jsonObj.remove(MDA.PAGE_QUERY_INFO);
			}
			PlanProject planProject = JsonUtil.jsonToBean(jsonObj.toString(), PlanProject.class);

			Map<String,Object> param = new HashMap<String,Object>();
			param.put("planProject", planProject);
			if(page != null){
				param.put("page", page);
				PageHelper.startPage(page.getPageNumber(), page.getPageSize());
			}
			List<PlanProject> list = planProjectQueryDAO.queryPlanProjList(param);
			// 2.1获取资金信息
			planProjJoinFoundSource(list);
			// 2.2获取纵向统计资金
			List<PlanProject> allList = planProjectQueryDAO.queryPlanProjList(param);
			List<Map<String,Object>> statsList = null;
			if(allList != null && allList.size() > 0){
				statsList = planProjectQueryDAO.queryPlanProjFoundSourceStats(allList);
			}
			double buTotal = 0.0;//部补助
			double shengTotal = 0.0;//省财政
			double gaoTotal = 0.0;//高速水运融资
			double shiTotal = 0.0;//市州配套
			double qiTotal = 0.0;//企业自筹
			if(statsList != null && statsList.size() > 0){
				for(Map<String,Object> map : statsList){
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_BU)){
						buTotal = Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_SHENG)){
						shengTotal = Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_GAO)){
						gaoTotal =Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_SHI)){
						shiTotal =Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_QI)){
						qiTotal =Double.parseDouble(map.get("total").toString());
					}
				}
			}
			double allTotal = (double)Math.round((buTotal + shengTotal + gaoTotal + shiTotal + qiTotal)*100)/100;;
			
			List<ProjStats> planProjStatsList = new ArrayList<ProjStats>();
			ProjStats stats = new ProjStats();
			stats.setFundSourceBu(buTotal);
			stats.setFundSourceGao(gaoTotal);
			stats.setFundSourceQi(qiTotal);
			stats.setFundSourceShi(shiTotal);
			stats.setFundSourceSheng(shengTotal);
			stats.setTotal(allTotal);
			stats.setDescription("合计:");
			planProjStatsList.add(stats);
			
			
			
			if(page != null){
				page.setTotalPages(((Page<PlanProject>)list).getPages());
				page.setTotal(((Page<PlanProject>)list).getTotal());
			}else{
				page = new PageQuery<PlanProject>();
			}
			page.setRows(list);
			page.setFooter(planProjStatsList);
			
			return page;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}
	
	/**
	 * 
	 * 规划工程获取资金信息
	 * @param list 
	 */
	private void planProjJoinFoundSource(List<PlanProject> list) {
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_PLAN);//规划项目
		for(PlanProject planProj : list){
			fundSource.setFundSourceObj(planProj.getPlanProjId());
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
			for(FundSource fs : fundSourceList){
				switch (fs.getFundSourceType()) {
				case "10":
					planProj.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
					break;
				case "20":
					planProj.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
					break;
				case "30":
					planProj.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
					break;
				case "40":
					planProj.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
					break;
				case "50":
					planProj.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
					break;
				default:
					break;
				}
			}
		}
	}

	@Override
	public List<PlanProject> queryAllPlanProjList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			PlanProject planProject = JsonUtil.jsonToBean(inJson, PlanProject.class);

			Map<String,Object> param = new HashMap<String,Object>();
			param.put("planProject", planProject);

			List<PlanProject> list = planProjectQueryDAO.queryPlanProjList(param);
			FundSource fundSource = new FundSource();
			fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_PLAN);//实施项目
			for(PlanProject planProj : list){
				fundSource.setFundSourceObj(planProj.getPlanProjId());
				List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
				for(FundSource fs : fundSourceList){
					switch (fs.getFundSourceType()) {
						case "10":
							planProj.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
							break;
						case "20":
							planProj.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
							break;
						case "30":
							planProj.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
							break;
						case "40":
							planProj.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
							break;
						case "50":
							planProj.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
							break;
						default:
							break;
					}

				}
			}
			return list;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}

	@Override
	public PlanProject queryPlanProjDetail(PlanProject planProjParam) {
		PlanProject planProj = planProjectQueryDAO.queryPlanProjDetail(planProjParam);
		
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_PLAN);//实施项目
		fundSource.setFundSourceObj(planProjParam.getPlanProjId());
		List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
		for(FundSource fs : fundSourceList){
			switch (fs.getFundSourceType()) {
			case "10":
				planProj.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
				break;
			case "20":
				planProj.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
				break;
			case "30":
				planProj.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
				break;
			case "40":
				planProj.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
				break;
			case "50":
				planProj.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
				break;
			default:
				break;
			}
			
		}
		
		return planProj;
	}

	@Override
	public PageQuery<ImplementProject> queryImpleProjList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			PageQuery<ImplementProject> page = null;
			JSONObject jsonObj = JSONObject.fromObject(inJson);
			if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
				JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
				page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
				jsonObj.remove(MDA.PAGE_QUERY_INFO);
			}
			
			ImplementProject impleProj = JsonUtil.jsonToBean(jsonObj.toString(), ImplementProject.class);

			Map<String,Object> param = new HashMap<String,Object>();
			param.put("impleProj", impleProj);
			if(page != null){
				param.put("page", page);
				PageHelper.startPage(page.getPageNumber(), page.getPageSize());
			}
			// 2.查询实施项目 父级
			List<ImplementProject> parentList = implementProjQueryDAO.queryImpleProjList(param);
			// 2.1获取资金信息
			impleProjJoinFoundSource(parentList);
			
			// 2.2 获取项目前期工作情况
			impleProjJoinProjStage(parentList);
			
			// 2.3获取纵向统计资金
			List<ImplementProject> allList = implementProjQueryDAO.queryImpleProjList(param);
			List<Map<String,Object>> statsList = null;
			if(allList != null && allList.size() > 0){
				statsList = implementProjQueryDAO.queryImpleProjFoundSourceStats(allList);
			}
			double buTotal = 0.0;//部补助
			double shengTotal = 0.0;//省财政
			double gaoTotal = 0.0;//高速水运融资
			double shiTotal = 0.0;//市州配套
			double qiTotal = 0.0;//企业自筹
			if(statsList != null && statsList.size() > 0){
				for(Map<String,Object> map : statsList){
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_BU)){
						buTotal = Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_SHENG)){
						shengTotal = Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_GAO)){
						gaoTotal =Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_SHI)){
						shiTotal =Double.parseDouble(map.get("total").toString());
					}
					if(map.get("fundSourceType").toString().equals(MDA.FUND_SOURCE_TYPE_QI)){
						qiTotal =Double.parseDouble(map.get("total").toString());
					}
				}
			}
			double allTotal = (double)Math.round((buTotal + shengTotal + gaoTotal + shiTotal + qiTotal)*100)/100;;
			
			List<ProjStats> impleProjStatsList = new ArrayList<ProjStats>();
			ProjStats stats = new ProjStats();
			stats.setFundSourceBu(buTotal);
			stats.setFundSourceGao(gaoTotal);
			stats.setFundSourceQi(qiTotal);
			stats.setFundSourceShi(shiTotal);
			stats.setFundSourceSheng(shengTotal);
			stats.setTotal(allTotal);
			stats.setLinkmanName("合计:");
			impleProjStatsList.add(stats);
			
			// 3.查询子实施项目列表
			ImplementProject impleProjQuery = new ImplementProject();
			for(ImplementProject ip : parentList){
				impleProjQuery.setParentImpleProjId(ip.getImpleProjId());
				param.put("impleProj", impleProjQuery);
//				param.put("page", page);
				// 3.1查询实施项目 子集
				List<ImplementProject> list = implementProjQueryDAO.queryImpleProjList(param);
				// 3.2获取资金信息
				impleProjJoinFoundSource(list);
				ip.setSubList(list);
			}
			
			// 4.结果返回
			if(page != null){
				page.setTotalPages(((Page<ImplementProject>)parentList).getPages());
				page.setTotal(((Page<ImplementProject>)parentList).getTotal());
			}else{
				page = new PageQuery<ImplementProject>();
			}
			PageInfo pageInfo = new PageInfo(parentList);
			page.setRows(parentList);
			page.setFooter(impleProjStatsList);
			page.setTotal(pageInfo.getTotal());
			return page;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}
	
	/**
	 * 
	 * 实施项目获取项目前期工作情况（项目阶段信息表状态为30）
	 * @param list 
	 */
	private void impleProjJoinProjStage(List<ImplementProject> list) {
		ProjectStage projStage = new ProjectStage();
		// modify by xuwb 是否当前项目阶段 都给显示出来
//		projStage.setStatusCd(MDA.PROJECT_STAGE_STATUS_CD_FINISH);//已完工
		for(ImplementProject ip : list){
			projStage.setImpleProjId(ip.getImpleProjId());
			List<ProjectStage> projStageList = implementProjQueryDAO.queryImpleProjStageList(projStage);
			StringBuffer sb =  new StringBuffer();
			for(ProjectStage temp : projStageList){
				sb.append(temp.getProjStateName()).append(":").append(temp.getApprovalInfo()).append(";");
			}
			ip.setPreWorkSituation(sb.toString());
		}
	}

	@Override
	public List<ImplementProject> queryAllImpleProjList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			ImplementProject impleProj = JsonUtil.jsonToBean(inJson, ImplementProject.class);

			Map<String,Object> param = new HashMap<String,Object>();
			param.put("impleProj", impleProj);
			// 2.查询实施项目 父级
			List<ImplementProject> parentList = implementProjQueryDAO.queryAllImpleProjList(param);
			// 2.1获取资金信息
			impleProjJoinFoundSource(parentList);

			// 3.查询子实施项目列表
			ImplementProject impleProjQuery = new ImplementProject();
			for(ImplementProject ip : parentList){
				impleProjQuery.setParentImpleProjId(ip.getImpleProjId());
				param.put("impleProj", impleProjQuery);
				// 3.1查询实施项目 子集
				List<ImplementProject> list = implementProjQueryDAO.queryImpleProjList(param);
				// 3.2获取资金信息
				impleProjJoinFoundSource(list);
				ip.setSubList(list);
			}

			return parentList;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}

	@Override
	public ImplementProject queryImpleProjDetail(ImplementProject req) throws Exception{
		try {
			Map<String,Object> param = new HashMap<String,Object>();
			if(null==req){
				req = new ImplementProject();
			}
			param.put("impleProj", req);
			ImplementProject implementProjectDetail = implementProjQueryDAO.queryImpleProjDetail(param);
			return implementProjectDetail;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}

	@Override
	public ImplementProject queryImpleProjDetailByRelated(Map<String,Object> param) throws Exception{
		try {
			ImplementProject implementProjectDetail = implementProjQueryDAO.queryImpleProjDetailByRelated(param);
			return implementProjectDetail;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}

	/**
	 * 
	 * 实施项目获取资金信息
	 * @param list 
	 */
	private void impleProjJoinFoundSource(List<ImplementProject> list) {
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_IMPLEMENT);//实施项目
		for(ImplementProject ip : list){
			fundSource.setFundSourceObj(ip.getImpleProjId());
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
			for(FundSource fs : fundSourceList){
				switch (fs.getFundSourceType()) {
				case "10":
					ip.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
					break;
				case "20":
					ip.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
					break;
				case "30":
					ip.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
					break;
				case "40":
					ip.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
					break;
				case "50":
					ip.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
					break;
				default:
					break;
				}
				
			}
		}
	}

	@Override
	public List<BusiConstParamVal> queryConstListByCode(String constCode) {
		return implementProjQueryDAO.queryConstListByCode(constCode);
	}

	@Override
	public List<ProjectStage> queryImpleProjStageList(ProjectStage projStage) {
		List<ProjectStage> list = implementProjQueryDAO.queryImpleProjStageList(projStage);
		
		// 获取资金信息
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_STAGE);
		for(ProjectStage temp : list){
			fundSource.setFundSourceObj(temp.getProjStageId());
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
			for(FundSource fs : fundSourceList){
				switch (fs.getFundSourceType()) {
				case "10":
					temp.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
					break;
				case "20":
					temp.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
					break;
				case "30":
					temp.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
					break;
				case "40":
					temp.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
					break;
				case "50":
					temp.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
					break;
				default:
					break;
				}
			}
		}
		
		return list;
	}

	@Override
	public PageQuery<ImplementProject> queryImpleDeclareSetList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			PageQuery<ImplementProject> page = null;
			JSONObject jsonObj = JSONObject.fromObject(inJson);
			if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
				JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
				page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
				jsonObj.remove(MDA.PAGE_QUERY_INFO);
			}
			
			ImplementProject impleProj = JsonUtil.jsonToBean(jsonObj.toString(), ImplementProject.class);

			Map<String,Object> param = new HashMap<String,Object>();
			param.put("impleProj", impleProj);
			if(page != null){
				param.put("page", page);
				PageHelper.startPage(page.getPageNumber(), page.getPageSize());
			}
			List<ImplementProject> list = implementProjQueryDAO.queryImpleDeclareSetList(param);
			// 2.1获取资金信息
			impleProjJoinFoundSource(list);
			
			// 2.2 获取项目前期工作情况
			impleProjJoinProjStage(list);
			
			// 4.结果返回
			if(page != null){
				page.setTotalPages(((Page<ImplementProject>)list).getPages());
				page.setTotal(((Page<ImplementProject>)list).getTotal());
			}else{
				page = new PageQuery<ImplementProject>();
			}
			page.setRows(list);
			
			return page;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}

	@Override
	public PageQuery<ProjProceSubmitListRespVo> queryProjProceSubmitList(String inJson) throws Exception {
		try {
			// 1.json格式校验
			if (!JsonUtil.jsonValidate(inJson)) {
				throw new BaseException(
						new StringBuffer().append("字符串： ").append(inJson).append("不符合JSON格式").toString());
			}
			PageQuery<ProjProceSubmitListRespVo> page = null;
			JSONObject jsonObj = JSONObject.fromObject(inJson);
			if (jsonObj.containsKey(MDA.PAGE_QUERY_INFO)) {
				JSONObject pageInfo = jsonObj.getJSONObject(MDA.PAGE_QUERY_INFO);
				page = JsonUtil.jsonToBean(pageInfo.toString(), PageQuery.class);
				jsonObj.remove(MDA.PAGE_QUERY_INFO);
			}
			ProjProceSubmitListReqVo reqVo = JsonUtil.jsonToBean(jsonObj.toString(), ProjProceSubmitListReqVo.class);
			String oper = reqVo.getOperation();
			if(oper != null && "query".equals(oper)){
				reqVo.setIfSubmit("1");
			}
			
			Map<String,Object> param = new HashMap<String,Object>();
			param.put("reqVo", reqVo);
			if(page != null){
				param.put("page", page);
				PageHelper.startPage(page.getPageNumber(), page.getPageSize());
			}
			List<ProjProceSubmitListRespVo> list = implementProjQueryDAO.queryProjProceSubmitList(param);
			
			// 获取资金信息
			projProceJoinFoundSource(list);
			
			// 获取项目前期工作情况
			projProceJoinProjStage(list);
			
			// 关联附件
			 for(ProjProceSubmitListRespVo temp : list){
				 String impleProjId = temp.getImpleProjId();
				if(!StringUtil.isEmpty(impleProjId)){
					Map<String,Object> paramFile = new HashMap<String,Object>();
					paramFile.put("uploadObjId",impleProjId);
					List<FileUpload> fileUploadList = fileQueryDAO.queryFileUploadsByCond(paramFile);
					if(fileUploadList != null && fileUploadList.size() > 0){
						List<FileVo> fileVos = new ArrayList<FileVo>();
						for(FileUpload fileUpload : fileUploadList) {
							FileVo fileVo = new FileVo();
							fileVos.add(fileVo);
							fileVo.setAttachFullName(fileUpload.getUploadName());
							fileVo.setAttachPath(fileUpload.getFilePath());
							fileVo.setUploadId(fileUpload.getUploadId());
							fileVo.setUploadObjId(fileUpload.getUploadObjId());
							fileVo.setUploadObjType(fileUpload.getUploadObjType());
						}
						temp.setFileList(fileVos);
					}
				}
			}
			
			// 4.结果返回
			if(page != null){
				page.setTotalPages(((Page<ProjProceSubmitListRespVo>)list).getPages());
				page.setTotal(((Page<ProjProceSubmitListRespVo>)list).getTotal());
			}else{
				page = new PageQuery<ProjProceSubmitListRespVo>();
			}
			page.setRows(list);
			
			return page;
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error(ReturnsUtil.getStackTrackMessage(e));
			}
			throw new Exception(ReturnsUtil.getStackTrackMessage(e));
		}
	}
	
	/**
	 * 
	 * 项目报送管理获取项目前期工作情况. 
	 * @param list 
	 * @author xuwb
	 */
	private void projProceJoinProjStage(List<ProjProceSubmitListRespVo> list) {
		ProjectStage projStage = new ProjectStage();
		projStage.setStatusCd(MDA.PROJECT_STAGE_STATUS_CD_FINISH);//已完工
		for(ProjProceSubmitListRespVo ip : list){
			projStage.setImpleProjId(ip.getImpleProjId());
			List<ProjectStage> projStageList = implementProjQueryDAO.queryImpleProjStageList(projStage);
			StringBuffer sb =  new StringBuffer();
			for(ProjectStage temp : projStageList){
				sb.append(temp.getProjStateName()).append(":").append(temp.getApprovalInfo()).append(";");
			}
			ip.setPreWorkSituation(sb.toString());
		}		
	}

	/**
	 * 
	 * 项目报送管理获取项目资金信息.  
	 * @param list 
	 * @author xuwb
	 */
	private void projProceJoinFoundSource(List<ProjProceSubmitListRespVo> list) {
		FundSource fundSource = new FundSource();
		fundSource.setFundSourceObjType(MDA.FUND_SOURCE_OBJ_TYPE_IMPLEMENT);//实施项目
		for(ProjProceSubmitListRespVo ip : list){
			fundSource.setFundSourceObj(ip.getImpleProjId());
			List<FundSource> fundSourceList = fundSourceQueryDAO.queryFoundSource(fundSource);
			for(FundSource fs : fundSourceList){
				switch (fs.getFundSourceType()) {
				case "10":
					ip.setFundSourceBu(Double.parseDouble(fs.getFundVal()));
					break;
				case "20":
					ip.setFundSourceSheng(Double.parseDouble(fs.getFundVal()));
					break;
				case "30":
					ip.setFundSourceGao(Double.parseDouble(fs.getFundVal()));
					break;
				case "40":
					ip.setFundSourceShi(Double.parseDouble(fs.getFundVal()));
					break;
				case "50":
					ip.setFundSourceQi(Double.parseDouble(fs.getFundVal()));
					break;
				default:
					break;
				}
				
			}
		}
	}
}
